package aes.general.test;

import java.io.IOException;
import java.util.ArrayList;

import aes.client.AesClient;
import aes.general.Msg;
import aes.general.Question;
import aes.general.QuestionControl;
import fit.ActionFixture;



public class AddQuestion extends ActionFixture {

	private Question q = new Question();
	private ArrayList<String> answer = new ArrayList<String>();
	


	public void setQuestionNumber(String num)
	{
		q.setQId(q.getSubject() + num);
	}	

	public void setQuestionSubject(String subj)
	{
		q.setSubject(subj);
	}
	
	public void setQuestion(String qst)
	{
		q.setQuestion(qst);	
	}
	
	public void setDescription(String dst)
	{
		q.setDescription(dst);	
	}
	
	public void setAnswer1 (String ans)
	{
		answer.add(0, ans);
	}
	
	public void setAnswer2 (String ans)
	{
		answer.add(1, ans);
	}
	public void setAnswer3 (String ans)
	{
		answer.add(2, ans);
	}
	public void setAnswer4 (String ans)
	{
		answer.add(3, ans);
	}
	
	public void setAnswerArray() 
	{
		q.setAnswer(answer);
		
	}
	
	public void setCorrect (int correct)
	{
		q.setCorrectAns(correct);
	}
	
	public void setAuthor(String author) 
	{
		q.setAuthor(author);
	}
	
	public void saveQuestion()
	{		
		try {
			AesClient client = new AesClient("localhost", 3606);
			client.openConnection();
			Msg request = new Msg(q, "400");
			client.handleMessageFromClientUI(request);
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
	}
	
	public boolean checkExist()
	{
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		QuestionControl qc = new QuestionControl(null);
		return qc.isQstrec();
		
	}
	
}
